Type.registerNamespace("AjaxControlToolkitCustom");

AjaxControlToolkitCustom.ConfirmButtonHiddenEventArgs = function(a) 
{
	AjaxControlToolkitCustom.ConfirmButtonHiddenEventArgs.initializeBase(this);
	this._confirmed = a
};

AjaxControlToolkitCustom.ConfirmButtonHiddenEventArgs.prototype = { get_confirmed: function() {
		return this._confirmed
	} 
};

AjaxControlToolkitCustom.ConfirmButtonHiddenEventArgs.registerClass("AjaxControlToolkitCustom.ConfirmButtonHiddenEventArgs", Sys.EventArgs);
AjaxControlToolkitCustom.ConfirmButtonBehavior = function(c) { 
	var b = null, a = this;
	AjaxControlToolkitCustom.ConfirmButtonBehavior.initializeBase(a, [c]);
	a._ConfirmTextValue = b;
	a._OnClientCancelValue = b;
	a._ConfirmOnFormSubmit = false;
	a._displayModalPopupID = b;
	a._postBackScript = b;
	a._clickHandler = b;
	a._oldScript = b 
 };
 
 AjaxControlToolkitCustom.ConfirmButtonBehavior.prototype = { 
 
	initialize: function() {
		var a = this;
		AjaxControlToolkitCustom.ConfirmButtonBehavior.callBaseMethod(a, "initialize");
		var b = a.get_element();
		a._clickHandler = Function.createDelegate(a, a._onClick);
		$addHandler(b, "click", a._clickHandler);
		a._oldScript = b.getAttribute("onclick");

		if (a._oldScript) 
			b.setAttribute("onclick", null);

		if (a._ConfirmOnFormSubmit && typeof WebForm_OnSubmit == "function" && !AjaxControlToolkitCustom.ConfirmButtonBehavior._originalWebForm_OnSubmit)
			if (AjaxControlToolkitCustom.TextBoxWatermarkBehavior && AjaxControlToolkitCustom.TextBoxWatermarkBehavior._originalWebForm_OnSubmit) {
				AjaxControlToolkitCustom.ConfirmButtonBehavior._originalWebForm_OnSubmit = AjaxControlToolkitCustom.TextBoxWatermarkBehavior._originalWebForm_OnSubmit;

			AjaxControlToolkitCustom.TextBoxWatermarkBehavior._originalWebForm_OnSubmit=AjaxControlToolkitCustom.ConfirmButtonBehavior.WebForm_OnSubmit
		}
		else{
			AjaxControlToolkitCustom.ConfirmButtonBehavior._originalWebForm_OnSubmit=WebForm_OnSubmit;
			WebForm_OnSubmit=AjaxControlToolkitCustom.ConfirmButtonBehavior.WebForm_OnSubmit
		}
	},

	dispose:function(){
		var a=this;
		if(a._clickHandler){
			$removeHandler(a.get_element(),"click",a._clickHandler);
			a._clickHandler=null
		}
		if(a._oldScript){
			a.get_element().setAttribute("onclick",a._oldScript);
			a._oldScript=null
		}
		AjaxControlToolkitCustom.ConfirmButtonBehavior.callBaseMethod(a,"dispose")
	},

	_onClick:function(e){
		var a=this;
		if(a.get_element()&&!a.get_element().disabled)
			if(a._ConfirmOnFormSubmit)
				AjaxControlToolkitCustom.ConfirmButtonBehavior._clickedBehavior=a;
			else if(!a._displayConfirmDialog()){
				e.preventDefault();
				return false
			}
			else if(a._oldScript)
				if(String.isInstanceOfType(a._oldScript))
					eval(a._oldScript);
			else if(typeof a._oldScript=="function")
				a._oldScript()
	},

	_displayConfirmDialog:function(){
		var a=this,c=new Sys.CancelEventArgs;
		a.raiseShowing(c);
		if(c.get_cancel())
			return;
		if(a._displayModalPopupID){
			var b=$find(a._displayModalPopupID);
		if(!b)
			throw Error.argument("displayModalPopupID",String.format(AjaxControlToolkitCustom.Resources.CollapsiblePanel_NoControlID,a._displayModalPopupID));
			b.set_OnOkScript("$find('"+a.get_id()+"')._handleConfirmDialogCompletion(true);");
			b.set_OnCancelScript("$find('"+a.get_id()+"')._handleConfirmDialogCompletion(false);");
			b.show();
			return false
		}
		else{
			var d=window.confirm(a._ConfirmTextValue);
			a._handleConfirmDialogCompletion(d);
			return d
		}
	},

	_handleConfirmDialogCompletion:function(result){
		var a=this;
		a.raiseHidden(new AjaxControlToolkitCustom.ConfirmButtonHiddenEventArgs(result));
		if(result){
			if(a._postBackScript)eval(a._postBackScript)
		}
		else if(a._OnClientCancelValue)window[a._OnClientCancelValue]()
	},

	get_OnClientCancel:function(){
		return this._OnClientCancelValue
	},

	set_OnClientCancel:function(a){
		if(this._OnClientCancelValue!=a){
			this._OnClientCancelValue=a;
			this.raisePropertyChanged("OnClientCancel")
			}
		},

	get_ConfirmText:function(){
		return this._ConfirmTextValue
	},

	set_ConfirmText:function(a){
		if(this._ConfirmTextValue!=a){
			this._ConfirmTextValue=a;
			this.raisePropertyChanged("ConfirmText")
		}
	},

	get_ConfirmOnFormSubmit:function(){
		return this._ConfirmOnFormSubmit
	},

	set_ConfirmOnFormSubmit:function(a){
		if(this._ConfirmOnFormSubmit!=a){
			this._ConfirmOnFormSubmit=a;
			this.raisePropertyChanged("ConfirmOnFormSubmit")
		}
	},

	get_displayModalPopupID:function(){
		return this._displayModalPopupID
	},

	set_displayModalPopupID:function(a){
		if(this._displayModalPopupID!=a){
			this._displayModalPopupID=a;
			this.raisePropertyChanged("displayModalPopupID")
		}
	},

	get_postBackScript:function(){
		return this._postBackScript
	},

	set_postBackScript:function(a){
			if(this._postBackScript!=a){
			this._postBackScript=a;
			this.raisePropertyChanged("postBackScript")
		}
	},

	add_showing:function(a){
		this.get_events().addHandler("showing",a)
	},

	remove_showing:function(a){
		this.get_events().removeHandler("showing",a)
	},

	raiseShowing:function(b){
		var a=this.get_events().getHandler("showing");
		if(a)
			a(this,b)
	},

	add_hidden:function(a){
		this.get_events().addHandler("hidden",a)
	},

	remove_hidden:function(a){
		this.get_events().removeHandler("hidden",a)
	},

	raiseHidden:function(b){
		var a=this.get_events().getHandler("hidden");
	if(a)
		a(this,b)
	}
};

AjaxControlToolkitCustom.ConfirmButtonBehavior.registerClass("AjaxControlToolkitCustom.ConfirmButtonBehavior",AjaxControlToolkitCustom.BehaviorBase);
AjaxControlToolkitCustom.ConfirmButtonBehavior.WebForm_OnSubmit=function(){
	var a=AjaxControlToolkitCustom.ConfirmButtonBehavior._originalWebForm_OnSubmit();
	if(a&&AjaxControlToolkitCustom.ConfirmButtonBehavior._clickedBehavior)
		a=AjaxControlToolkitCustom.ConfirmButtonBehavior._clickedBehavior._displayConfirmDialog();
		AjaxControlToolkitCustom.ConfirmButtonBehavior._clickedBehavior=null;
	return a
};
